﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
using Model.Product;
using BLL.Product;
using Common;
namespace DAGG.Controllers.Product
{
    public class ProductController : Controller
    {
        ProductBLL bll = new ProductBLL();
        //
        // GET: /Product/
        public ActionResult Index(int page = 1)
        {
            IPagedList<ProductModel> modelInfoList = bll.GetList().ToPagedList(page, 10);
            //将数据分页后返回页面（这里可以在取数据的时候先分页后，再使用ToPagedList实现分页
         
            ViewBag.MyPageList = modelInfoList;
            return View();
        }

        public ActionResult Edit() { return View(); }
        public ActionResult EditNew(string id) {
            ProductModel model = new ProductModel();
            //获取对象回显信息
            model = bll.GetModel(id);
            return View(model); 
        
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveData(ProductModel product) {
           
             bll.SaveData(product);
             return Redirect("/Product/Index");
        }
        /// <summary>
        /// 删除实体类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelModel(string id) {
             ResultEntity entitye = bll.DelModel(id);
             return Json(entitye, JsonRequestBehavior.AllowGet);
        }
	}
}